package com.cykj.page02;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @BelongsProject: HandTomcat
 * @BelongsPackage: com.cykj
 * @Author: 阿隆
 * @CreateTime: 2025-10-18 11:35
 * @Description: 简易客户端
 * @Version: 1.0
 */
public class MyClient {
    public static void main(String[] args) {
        try {

            Socket socket = new Socket("127.0.0.1", 9090);

            Scanner sc = new Scanner(System.in);

            //循环
            while (true) {
                OutputStream os = socket.getOutputStream();

                System.out.println("请输入要发送个后台的消息");
                //接收控制台的字符串
                String msg = sc.next();
                //写出数据 ==> 写到通信管道
                os.write(msg.getBytes());
            }


        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
